﻿using System;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Domain.Services;

namespace YaAppoint.Devices
{
    public class DeviceTypeManager(IRepository<Device,Guid> deviceRepository,
                                   IRepository<DeviceType,Guid> deviceTypeRepository):DomainService
    {
        private readonly IRepository<Device, Guid> _deviceRepository = deviceRepository;
        private readonly IRepository<DeviceType, Guid> _deviceTypeRepository = deviceTypeRepository;

        public async Task DeleteAsync(Guid id)
        {
            var deviceType = await _deviceTypeRepository.FirstOrDefaultAsync(x => x.Id == id);
            if (deviceType != null)
            {
                await _deviceRepository.DeleteAsync(x => x.DeviceTypeId == id);
                await _deviceTypeRepository.DeleteAsync(deviceType);
            }
        }
    }
}
